package com.kunbo.cn.app.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.kunbo.cn.app.service.NoticeOfArrivalService;
import com.kunbo.cn.entity.core.logistics.TrafficUnit;
import com.kunbo.cn.entity.core.purchase.OrderWayBill;
import com.kunbo.cn.service.core.logistics.TrafficUnitService;
import com.kunbo.cn.service.core.purchase.OrderWayBillService;
import com.kunbo.cn.service.core.purchase.PurchaseOrderService;
import com.kunbo.cn.util.date.SDate;
import com.kunbo.cn.util.retu.BuildBean;
import com.kunbo.cn.util.retu.ResultBean;

/**
 * 供应商app
 * @author  编写人:刘义
 * @date 时间:2019年3月25日上午11:10:18
 */
@RestController
@RequestMapping("/supplierapp")
public class SupplierAppController {
	
	
	@Autowired
	private PurchaseOrderService serviceOrder;
	@Autowired
	private TrafficUnitService unitService;
	@Autowired
	private OrderWayBillService wayBillService;
	@Autowired
	private NoticeOfArrivalService service;
	
	
	
	
	/**
	 * 首页获取订单
	 * @param startTime
	 * @param endTime
	 * @param orderCode
	 * @param material
	 * @param page
	 * @param pageSize
	 * @return
	 */
	@PostMapping("/selOrder")
	public ResultBean<List<Map<String,Object>>> selOrder(
			@RequestParam("startTime")String startTime,
			@RequestParam("endTime")String endTime,
			@RequestParam("orderCode")String orderCode,
			@RequestParam("material")String material,
			@RequestParam("placeoftransportation")Integer placeoftransportation,
			@RequestParam("page")Integer page,
			@RequestParam("pageSize")Integer pageSize
			){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "success", "error", serviceOrder.selOrder(startTime,endTime,orderCode,material,placeoftransportation,page,pageSize));
		
	}
	
	
	
	/**
	 * 新增供应商
	 * @param affiliate
	 * @param unit_name
	 * @param phone
	 * @param address
	 * @return
	 */
	@PostMapping("/saveTrafficUnit")
	public ResultBean<TrafficUnit> saveTrafficUnit(
			@RequestParam("affiliate")String affiliate,
			@RequestParam("unit_name")String unit_name,
			@RequestParam("phone")String phone,
			@RequestParam("address")String address,
			@RequestParam("unit_number")String unit_number
			){
		ResultBean<TrafficUnit> result = new ResultBean<TrafficUnit>();
		return BuildBean.buildResult(result, "success", "error", unitService.save(affiliate,unit_name,phone,address,unit_number));
	}
	
	@GetMapping("/createCode")
	
	
	public String createCode(){
		Map<String,Object> map=new HashMap<String,Object>();
		 String prex = "YS";
		 String noticeCode= prex+SDate.getSystemDateYMDHMSToString();
		return noticeCode;
	}
	
	
	
	/**
	 * 删除供应商
	 * @param id
	 * @return
	 */
	@PostMapping("/delTrafficUnit")
	public ResultBean<Boolean> delTrafficUnit(
			@RequestParam("id")String id
			){
		ResultBean<Boolean> result = new ResultBean<Boolean>();
		return BuildBean.buildResult(result, "success", "error", unitService.delTrafficUnit(id));
	}
	
	
	
	
	
	
	/**
	 * 查询供应商列表
	 * @param affiliate
	 * @return
	 */
	@PostMapping("/selTrafficUnit")
	public ResultBean<List<Map<String,Object>>> selTrafficUnit(
			@RequestParam("affiliate")String affiliate,
			@RequestParam("page")Integer page,
			@RequestParam("pageSize")Integer pageSize
			){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "success", "error", unitService.selTrafficUnit(affiliate,page,pageSize));
	}
	
	
	
	/**
	 * 分量生成运单
	 * @param uuid
	 * @param create_user_id
	 * @param wayBillCode
	 * @param source
	 * @param material
	 * @param order_quantity_to_be_sent
	 * @param supplier
	 * @param purchasing_unit
	 * @param purchase_waybill_freightvolume
	 * @param purchase_waybill_stayfreightvolume
	 * @param purchase_waybill_entrustedunit
	 * @return
	 */
	@PostMapping("/saveWayBillApp")
	public ResultBean<OrderWayBill> saveWayBillApp(
			@RequestParam("uuid")String uuid,
			@RequestParam("create_user_id")String create_user_id,
			@RequestParam("wayBillCode")String wayBillCode,
			@RequestParam("source")String source,
			@RequestParam("material")String material,
			@RequestParam("order_quantity_to_be_sent")Float order_quantity_to_be_sent,
			@RequestParam("supplier")String supplier,
			@RequestParam("purchasing_unit")String purchasing_unit,
			@RequestParam("purchase_waybill_freightvolume")Float purchase_waybill_freightvolume,
			@RequestParam("purchase_waybill_stayfreightvolume")Float purchase_waybill_stayfreightvolume,
			@RequestParam("purchase_waybill_entrustedunit")String purchase_waybill_entrustedunit
			){
		ResultBean<OrderWayBill> result = new ResultBean<OrderWayBill>();
		return BuildBean.buildResult(result, "success", "error", wayBillService.saveWayBillApp(uuid,create_user_id,wayBillCode,source,material,order_quantity_to_be_sent,supplier,purchasing_unit,purchase_waybill_freightvolume,purchase_waybill_stayfreightvolume,purchase_waybill_entrustedunit));
	}
	
	
	
	/**
	 * 获取运单
	 * @param supplier
	 * @param page
	 * @param pageSize
	 * @return
	 */
	@PostMapping("/selOrderWaybill")
	public ResultBean<List<Map<String,Object>>> selOrderWaybill(
			@RequestParam("supplier")String supplier,
			@RequestParam("page")Integer page,
			@RequestParam("pageSize")Integer pageSize
			){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "success", "error", wayBillService.selOrderWaybill(supplier,page,pageSize));
	}
	
	
	
	/**
	 * 获取通知单
	 * @param supplier
	 * @param page
	 * @param pageSize
	 * @return
	 */
	@PostMapping("/selOrderArrival")
	public ResultBean<List<Map<String,Object>>> selOrderArrival(
			@RequestParam("supplier")String supplier,
			@RequestParam("page")Integer page,
			@RequestParam("pageSize")Integer pageSize
			){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "success", "error", service.selOrderArrival(supplier,page,pageSize));
	}
	
	/**
	 * 获取通知单
	 * @param supplier
	 * @param page
	 * @param pageSize
	 * @return
	 */
	@PostMapping("/selOrderArrivalNotice")
	public ResultBean<List<Map<String,Object>>> selOrderArrivalNotice(
			@RequestParam("supplier")String supplier,
			@RequestParam("page")Integer page,
			@RequestParam("pageSize")Integer pageSize
			){
		ResultBean<List<Map<String,Object>>> result = new ResultBean<List<Map<String,Object>>>();
		return BuildBean.buildResult(result, "success", "error", service.selOrderArrivalNotice(supplier,page,pageSize));
	}
	
	
	
	
	
	
	

}
